5 Lecture
CS401
Midterm & Final Term Short Notes
Program Flow
Program flow refers to the order in which a program executes its instructions or statements. It determines how the program will execute and when specific actions will occur. Control structures, such as conditionals and loops, allow developers to
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
Which of the following control structures is used to execute a block of code repeatedly until a specific condition is met? A) if-else statement B) switch statement C) for loop D) while loop Answer: D) while loop Which of the following statements is used to transfer control to a different part of the program? A) if statement B) switch statement C) break statement D) continue statement Answer: C) break statement Which of the following control structures is used to execute a block of code repeatedly for a specific number of times? A) if-else statement B) switch statement C) for loop D) while loop Answer: C) for loop Which of the following control structures is used to execute a block of code based on the evaluation of a Boolean expression? A) if-else statement B) switch statement C) for loop D) while loop Answer: A) if-else statement Which of the following statements is used to terminate the current iteration of a loop and continue with the next iteration? A) if statement B) switch statement C) break statement D) continue statement Answer: D) continue statement Which of the following statements is used to define a default case in a switch statement? A) default: B) else: C) case default: D) case else: Answer: A) default: Which of the following control structures is used to execute a block of code only if a specific condition is true? A) if-else statement B) switch statement C) for loop D) while loop Answer: A) if-else statement Which of the following statements is used to exit a loop when a specific condition is met? A) if statement B) switch statement C) break statement D) continue statement Answer: C) break statement Which of the following control structures is used to execute a block of code repeatedly as long as a specific condition is true? A) if-else statement B) switch statement C) for loop D) while loop Answer: D) while loop Which of the following statements is used to transfer control to a different part of the program based on a specific condition? A) if statement B) switch statement C) break statement D) goto statement Answer: D) goto statement (Note: goto statement is generally discouraged in modern programming due to its potential to cause confusion and make code harder to read and maintain.)
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is program flow, and why is it important in programming? Answer: Program flow refers to the order in which a program executes its statements or instructions. It is important in programming because it allows developers to control the execution of a program and determine which statements are executed under different conditions. What are control structures in programming, and how do they affect program flow? Answer: Control structures are programming constructs that allow developers to control the flow of a program. They affect program flow by allowing developers to execute certain statements or instructions only under specific conditions. What is the difference between a for loop and a while loop, and when should each be used? Answer: A for loop is used when a specific number of iterations is known in advance, while a while loop is used when the number of iterations is not known in advance. A for loop is usually used when iterating over a collection of items, while a while loop is used when iterating until a certain condition is met. What is a conditional statement in programming, and how is it used to control program flow? Answer: A conditional statement is a programming construct that executes a block of code if a specific condition is met. It is used to control program flow by allowing developers to execute different blocks of code depending on the result of the condition. What is a switch statement in programming, and how is it used to control program flow? Answer: A switch statement is a programming construct that allows developers to execute different blocks of code based on the value of a variable or expression. It is used to control program flow by allowing developers to execute different blocks of code depending on the value of the variable or expression. What is a loop in programming, and how is it used to control program flow? Answer: A loop is a programming construct that allows developers to execute a block of code repeatedly until a specific condition is met. It is used to control program flow by allowing developers to execute the same block of code multiple times under different conditions. What is an if-else statement in programming, and how is it used to control program flow? Answer: An if-else statement is a programming construct that executes one block of code if a specific condition is met and another block of code if the condition is not met. It is used to control program flow by allowing developers to execute different blocks of code depending on the result of the condition. What is a break statement in programming, and how is it used to control program flow? Answer: A break statement is a programming construct that allows developers to terminate the current loop or switch statement and transfer control to a different part of the program. It is used to control program flow by allowing developers to exit a loop or switch statement early if a specific condition is met. What is a continue statement in programming, and how is it used to control program flow? Answer: A continue statement is a programming construct that allows developers to skip the current iteration of a loop and continue with the next iteration. It is used to control program flow by allowing developers to bypass specific iterations of a loop if a specific condition is met. What is a goto statement in programming, and why is it generally discouraged in modern programming? Answer: A goto statement is a programming construct that allows developers to transfer control to a different part of the program based on a specific condition. It is generally discouraged in modern programming because it can make code harder to read and maintain by creating non-linear program flow and potentially leading to unintended consequences.